package string_question.leecode.test115;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/8 9:14
 */
public class Solution2 {

    public int numDistinct(String s, String t) {
        if (s.length() < t.length()) return 0;
        int n1 = s.length();
        int n2 = t.length();
        int[][] dp = new int[n1 + 1][n2 + 1];
        for (int i = 0; i <= n1; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i <= n1; i++) {
            for (int j = 1; j <= i && j <= n2; j++) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[n1][n2];
    }
}
